<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./axios.js"></script>
  <script>
    const request = axios.create({
      baseURL: 'https://api.it120.cc/conner',
      timeout: 6000
    })
    // 给实例添加拦截器
    request.interceptors.request.use(function (config) {
      console.log('请求拦截器触发了', config);
      config.headers.token = 'fffeeeddd'
      return config;
    }, function (error) {
      // 请求失败拦截 不 return .catch无法触发
      return Promise.reject(error);
    });
    // 响应拦截器
    request.interceptors.response.use(function (res) {
      console.log('响应拦截器触发了', res);
      return res;
    }, function (error) {
      // 响应失败的拦截
      return Promise.reject(error);
    });
    const { createApp } = Vue;
    const app = createApp();

    const CommonHead = {
      template: `
        <div>
          <h2>头部组件</h2> 
          <ul>
            
          </ul> 
        </div>
      `,
      data() {
        return {
          blogs: [],
          cates: []
        }
      },
      methods: {
        fetchBlogs() {
          request({
            url: '/cms/news/list/v2',
            method: 'post',
            data: {
              a: 10,
              b: 20
            }
          }).then(res => {
            if (res.data.code === 0) {
              this.blogs = res.data.data.result
            }
          })
        },
        fetchCates() {
          request({
            url: '/cms/category/list',
            method: 'get',
            params: {
              a: 10,
              b: 20
            }
          }).then(res => {
            if (res.data.code === 0) {
              this.cates = res.data.data
            }
          })
        }
      },
      created() {
        this.fetchBlogs();
        this.fetchCates();
      }
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>

</html>

<!-- 

  {
    a: [1,2,3]
  }
  "a=1&a=2&a=3"
 -->